package cn.edu.lingnan.translation.service.impl;

import cn.edu.lingnan.translation.entity.Question;
import cn.edu.lingnan.translation.entity.vo.QuestionQueryVo;
import cn.edu.lingnan.translation.mapper.QuestionMapper;
import cn.edu.lingnan.translation.service.QuestionService;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class QuestionServiceImpl extends ServiceImpl<QuestionMapper, Question> implements QuestionService {
    @Override
    public IPage<Question> getQuestions(IPage<Question> page, Wrapper<Question> wrapper) {
        page.setRecords((List<Question>) baseMapper.selectPage(page, wrapper));
        return page;
    }

    @Override
    public Integer insertQuestions(Question question) {
        return baseMapper.insert(question);
    }

    @Override
    public Integer updateQuestions(List<String> id, Question question) {
        QueryWrapper<Question> wrapper = new QueryWrapper<>();
        wrapper.eq("id", id);
        return baseMapper.update(question, wrapper);
    }

    @Override
    public Integer deleteQuestions(List<String> id) {
        QueryWrapper<Question> wrapper = new QueryWrapper<>();
        wrapper.eq("id", id);
        return baseMapper.delete(wrapper);
    }
}
